// ActionScript file

// custom import classes
import events.EmployeeEvent;
import actionscript.Employee;
// flex framework classes
import mx.formatters.DateFormatter;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
            
// methods
private function init():void {
  // date formatter
  var dateFormatter:DateFormatter = new DateFormatter();
  dateFormatter.formatString = "EEEE, MMMM D, YYYY";
  dateDisplay.text = dateFormatter.format(new Date());
}
private function init2():void {
  // control label
  //control.text = titleBox.width.toString();
}
      
      private function populateDirectReports():ArrayCollection {
        var directReports:ArrayCollection = new ArrayCollection();
        var emp1:Employee = new Employee();
        emp1.id = "3245";
        emp1.title = "Programmer";
        emp1.firstName = "Svetlin";
        emp1.lastName = "Nakov";
        emp1.mail = "svetlin@nakov.com";
        directReports.addItem(emp1);
        var emp2:Employee = new Employee();
        emp2.id = "9327";
        emp2.title = "Assistant";
        emp2.firstName = "Marco";
        emp2.lastName = "Block-Berlitz";
        emp2.mail = "block@fu-belrin.de";
        directReports.addItem(emp2);
        
        return directReports;
      }
      
      private function searchEmployeeHandler(e:EmployeeEvent):void {
        var employeeResultData:ArrayCollection = e.employee as ArrayCollection;
        var employeeValueObjects:ArrayCollection = new ArrayCollection();
        for (var i:int = 0; i < employeeResultData.length; i++) {
          var employeeValueObject:Employee = new Employee();
          employeeValueObject.id = employeeResultData.getItemAt(i).id;
          employeeValueObject.title = employeeResultData.getItemAt(i).title;
          employeeValueObject.firstName = employeeResultData.getItemAt(i).firstname;
          employeeValueObject.lastName = employeeResultData.getItemAt(i).lastname;
          employeeValueObject.phoneNumber = employeeResultData.getItemAt(i).phone;
          employeeValueObject.mail = employeeResultData.getItemAt(i).mail;
          employeeValueObjects.addItem(employeeValueObject);
        }
        allEmployeesList.setDataProvider(employeeValueObjects);// Employee objects
        //allEmployeesList.setDataProvider(e.employee);
      }
      
      private function selectEmployeeEventHandler(e:EmployeeEvent):void {
        //directReportsList.visible = false;
        employeeDetails.selectedEmployee = e.employee;
        employeeDetails.visible = true;
      }
      
      private function clickDirectReportsHandler(e:Event):void {
        directReportsList.setDataProvider(populateDirectReports());
        directReportsList.visible = true;
      }
